package services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import persistence.CustomerMapper;

import models.Customer;

@Transactional
@Service
public class CustomerService {

//	List<Customer> getAllCustomers();
//	Customer getCustomerById(Integer cusId);
//	void insertCustomer(Customer cus);
//	void updateCustomer(Customer cus);
//	void deleteCustomer(Integer cusId);
	
	@Autowired
	private CustomerMapper customerMapper;
	
	public void insertCustomer(Customer cus) {
		try {
			customerMapper.insertCustomer(cus);
		} catch (Exception e) {
			e.getMessage();
		}
	}
	

	public Customer getCustomerById(Integer cusId) {
		try {
			return customerMapper.getCustomerById(cusId);
		} catch (Exception e) {
			e.getMessage();
		}
		return null;
	}
	
	public List<Customer> getCustomersLikeName(String name) {
		try {
			return customerMapper.getCustomersLikeName(name);
		} catch (Exception e) {
			e.getMessage();
		}
		return null;
	}
	
	public List<Customer> getAllCustomers() {
		try {
			List<Customer> cus= customerMapper.getAllCustomers();
			return cus;
		} catch (Exception e) {
			e.getMessage();
		}
		return null;
	}
	

	public void updateCustomer(Customer cus) {
		try {
			customerMapper.updateCustomer(cus);
		} catch (Exception e) {
			e.getMessage();
		}
	}
	

	public void deleteCustomer(Integer cusId) {
		try {
			customerMapper.deleteCustomer(cusId);
		} catch (Exception e) {
			e.getMessage();
		}
	}
}
